package com.ruoyi.produce.base.procedure.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.produce.base.procedure.domain.Procedure;
import com.ruoyi.produce.base.procedure.mapper.ProcedureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工序管理
 * 业务层执行
 * @author Drj 2021/6/28
 */
@Service
public class ProcedureServiceImpl implements IProcedureService {
    @Autowired
    private ProcedureMapper procedureMapper;

    /**
     * 查询工序管理内容
     *
     * @param procedure 条件
     * @return
     */
    @Override
    public List<Procedure> selectProcedureList(Procedure procedure) {
        return procedureMapper.selectProcedureList(procedure);
    }

    /**
     * 查询指定编号对应的工序
     *
     * @param procedureId
     * @return
     */
    @Override
    public Procedure selectProcedureById(String procedureId) {
        return procedureMapper.selectProcedureById(procedureId);
    }

    /**
     * 新增工序
     *
     * @param procedure
     * @return
     */
    @Override
    public int insertProcedure(Procedure procedure) {
        if (StringUtils.isNotNull(procedureMapper.selectProcedureById(procedure.getProcedureId()))) {
            //存在
            return 0;
        }
        return procedureMapper.insertProcedure(procedure);
    }

    /**
     * 更新工序
     *
     * @param procedure
     * @return
     */
    @Override
    public int updateProcedure(Procedure procedure) {
        if (!StringUtils.isNotNull(procedureMapper.selectProcedureById(procedure.getProcedureId()))) {
            //不存在
            return 0;
        }
        return procedureMapper.updateProcedure(procedure);
    }

    /**
     * 删除工序
     * 仅修改删除标志位
     *
     * @param procedure
     * @return
     */
    @Override
    public int updateProcedureDeleteFlag(Procedure procedure) {
        return procedureMapper.updateProcedureDeleteFlag(procedure);
    }
}
